﻿var DataverseAngular = angular.module('MyApp', []);


//Controller to fetch Order Items
//DataverseAngular.controller('OrderItemsController', function ($scope, OrderItemsService) {

//		getOrderItems();

//		function getOrderItems() {
//				OrderItemsService.GetOrderItems()
//					.success(function (data) {
//							$scope.orderitems = data;
//					})
//					.error(function (error) {
//							$scope.message = error.message;
//					});
//		}
//});



//Controller to fetch Customers
DataverseAngular.controller('CustomerController', function ($scope, CustomerService) {

		getCustomers();

		function getCustomers() {
				CustomerService.GetCustomers()
					.success(function (data) {
							$scope.customers = data;
					})
					.error(function (error) {
							$scope.message = error.message;
					});
		}
});



//Controller to fetch Orders
DataverseAngular.controller('OrdersController', function ($scope, OrdersService) {

		getOrders();

		function getOrders() {
				OrdersService.GetOrders()
					.success(function (data) {
							$scope.orders = data;
					})
					.error(function (error) {
							$scope.message = error.message;
					});
		}
});


//Controller to fetch Items
DataverseAngular.controller('ItemsController', function ($scope, ItemsService) {

	getItems();

	function getItems() {
		ItemsService.GetItems()
			.success(function(data) {
				$scope.items = data;
			})
			.error(function(error) {
				$scope.message = error.message;
			});
	}
});


//Service to display Customers
DataverseAngular.factory('CustomerService', ['$http', function ($http) {
		var CustomerService = {};
		CustomerService.GetCustomers = function () {
				return $http.get('/Home/GetCustomers');
		};
	return CustomerService;
}]);

//Service to display Items
DataverseAngular.factory('ItemsService', ['$http', function ($http) {
		var ItemsService = {};
		ItemsService.GetItems = function () {
				return $http.get('/Home/GetItems');
		};
		return ItemsService;
}]);


//Service to display Orders
DataverseAngular.factory('OrdersService', ['$http', function ($http) {
		var OrdersService = {};
		OrdersService.GetOrders = function () {
				return $http.get('/Home/GetOrders');
		};
		return OrdersService;
}]);




//Service to display Order Items
//DataverseAngular.factory('OrderItemsService', ['$http', function ($http) {
//		var OrderItemsService = {};
//		OrderItemsService.GetOrderItems = function () {
//				return $http.get('/Home/GetOrderItems/id');
//		};
//		return OrderItemsService;
//}]);
